<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>input防抖</title>
</head>

<body>
    <input type="text" id="myInput">
    <script>
        // 防抖函数
        const debounce = (fn, wait) => {
            let timer
            return () => {
                if (timer) clearTimeout(timer)
                timer = setTimeout(fn, wait)
            }
        }

        // 获取input框的内容
        const getValue = () => {
            console.log(input.value);
        }

        // 获取input标签
        let input = document.getElementById('myInput')
        
        // input框的输入事件
        input.oninput = debounce(getValue, 1000)


    </script>
</body>

</html>